<?php
/**
 * iCalcreator v2.10.23
 * copyright (c) 2007-2011 Kjell-Inge Gustafsson, kigkonsult
 * kigkonsult.se/iCalcreator/index.php
 * ical@kigkonsult.se
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

mysql_connect('localhost', 'root', '') or die(mysql_error());
mysql_select_db('aih') or die(mysql_error());

$id = (int)$_GET['rid'];
if($id>0) {
    $sql = "SELECT * FROM `cc_reminders` WHERE `id`=".$id;
    $rs = mysql_query($sql);
    $row = mysql_fetch_array($rs, MYSQL_ASSOC);
    if($row) {
        header('Content-Type: text/calendar; charset=utf-8');
        header('Content-Disposition: attachment; filename="aih-calendar.ics"; ');
        
        $dtstart_timestamp = strtotime($row['dtstart']);
        require_once 'iCalcreator.class.php';
        
        $v = new vcalendar( array( 'unique_id' => 'aih' ));   // initiate new CALENDAR

        $v->setProperty( 'X-WR-CALNAME', 'AIH calendar' );   // set some X-properties, name, content.. .
        $v->setProperty( 'X-WR-CALDESC', 'AIH - Payment schedule calendar' );
        $v->setProperty( 'X-WR-TIMEZONE', 'Europe/Stockholm' );

        $e = & $v->newComponent( 'vevent' );    // initiate a new EVENT
        $e->setProperty( 'dtstart', date('Y', $dtstart_timestamp), date('m', $dtstart_timestamp), date('d', $dtstart_timestamp), 00, 00, 00 );  // d m Y 00.00
        $e->setProperty( 'dtend', date('Y', $dtstart_timestamp), date('m', $dtstart_timestamp), date('d', $dtstart_timestamp), 23, 59, 59 );  // d m Y 23.59
        $e->setProperty( 'duration', 0, 0, 1 );     // 1 hour
        $e->setProperty( 'summary', $row['summary'] );  // describe the event
        $e->setProperty( 'location', 'AIH' );   // locate the event
        $e->setProperty( 'description', $row['description'] );  // describe the event

        $a = & $e->newComponent( 'valarm' );    // initiate ALARM
        $a->setProperty( 'action', 'DISPLAY' );     // set what to do
        $a->setProperty( 'description', $row['description'] ); // describe alarm
        $a->setProperty( 'trigger', array( 'min' => 30 ));  // set trigger one min before

        echo $v->createCalendar() ;     // generate and get output in string, for testing?
    }
    mysql_close();
    die();
}
mysql_close();
die();

?>